<?php

class Snoopy
{
	private $ch		= null;
	public $url	= null;
	private $option	= null;

	public function __construct( $url = 'http://www.baidu.com' ) {
		$this->setUrl($url);
	}

	public function setUrl($url)
	{
		$this->url	= $url;
		$this->ch	= curl_init( $this->url );
	}

	public function setOption( $option, $value ) {
		curl_setopt($this->ch, $option, $value );
		return $this;
	}

	public function setOptions( $options ) { //array $options
		if (!is_array( $options ))exit('The params for Gather::setOptions is not array.');
		foreach ( $options as $key => $val ) {
			$this->setOption( $key, $val );
		}
		return $this;
	}

	public function exec() {
		return curl_exec( $this->ch );
	}

	public function close() {
		curl_close( $this->ch );
	}

	public function fetch($url) {
		$this->setUrl($url);
		$this->setOption( CURLOPT_RETURNTRANSFER, true );
		return $this->exec();
	}
}